/*
 * Java CMPP API
 * Copyright (C) 2006 by Youming.Xu
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 526 Room, Hong Wa Building,22#,South Section1,
 * YiHuan Road,Sichuan,Chengdu,P.R.China
 * 
 * A copy of the LGPL can be viewed at http://www.gnu.org/copyleft/lesser.html
 * Java CMPP API author: xym008@gmail.net
 * Java CMPP API Homepage: http://cmppapi.sourceforge.net/
 * CMPPVersion.java,v 1.10 2006-7-316:43:41 xuym Exp
 */

package com.bci.cmpp.version;

/**
 * CMPPVersion.java
 * 
 * @author xuym
 * @version 1.0
 * 
 */
public abstract class CMPPVersion {

	/** Constant representing the message payload mandatory parameter. */
	public static final int MESSAGE_PAYLOAD = 5;

	/** Static CMPPVersion instance representing version v2.0. */
	public static final CMPPVersion V20 = new CMPPVersion20();

	/** Static Version instance representing version v3.0. */
	public static final CMPPVersion V30 = new CMPPVersion30();

	private int versionID = 0;

	/**
	 * Descriptive text for this protocol version. This value is used only to
	 * return a representative string from toString.
	 */
	private String versionString = null;

	/**
	 * Create a new CMPPVersion object.
	 */
	protected CMPPVersion(byte versionID, String versionString) {
		this.versionID = versionID;
		this.versionString = versionString;
	}

	/**
	 * Get an object representing the default version of the API, which is 2.0.
	 */
	public static final CMPPVersion getDefaultVersion() {
		return (V20);
	}

	public static final CMPPVersion getVersion(int id) throws VersionException {
		if (id == V20.getVersionID())
			return (V20);
		else if (id == V30.getVersionID())
			return (V30);
		else
			throw new VersionException("Unknown version id: 0x"
					+ Integer.toHexString(id));
	}

	/**
	 * Get the integer value for this protocol version object.
	 */
	public int getVersionID() {
		return (versionID);
	}

	/**
	 * Check if a version is older than this one. If <code>ver</code> is equal
	 * to this version, false will be returned.
	 */
	public boolean isOlder(CMPPVersion ver) {
		return (ver.versionID < this.versionID);
	}

	/**
	 * Check if a version is newer than this one. If <code>ver</code> is equal
	 * to this version, false will be returned.
	 */
	public boolean isNewer(CMPPVersion ver) {
		return (ver.versionID > this.versionID);
	}

	/**
	 * Test another CMPPVersion object for equality with this one.
	 */
	public boolean equals(Object obj) {
		if (obj instanceof CMPPVersion) {
			return (((CMPPVersion) obj).versionID == this.versionID);
		} else {
			return (false);
		}
	}

	/**
	 * Test <code>versionNum</code> is the numeric representation of this
	 * version.
	 */
	public boolean equals(int versionNum) {
		return (versionNum == this.versionID);
	}

	/**
	 * Return a descriptive string of this protocol version.
	 */
	public String toString() {
		return (versionString);
	}

	/**
	 * 
	 */
	public CMPPVersion() {
		super();
	}

	/**
	 * Get the maximum allowed length for a particular field. XXX allow an
	 * exception to be thrown for unidentified fields.
	 */
	public abstract int getMaxLength(int field);

	/**
	 * Determine if a particular command is supported by this protocol version.
	 * This method takes any valid CMPP command ID (for both requests and
	 * responses) and returns true or false based on whether the protocol
	 * version this object represents supports that command or not.
	 * 
	 * @param commandID
	 *            the CMPP command ID to check support for.
	 */
	//public abstract boolean isSupported(int commandID);

	/**
	 * Determine if this CMPP version supports optional parameters.
	 * 
	 * @return true if optional parameters are supported, false if they are not.
	 */
	//public abstract boolean isSupportOptionalParams();

	/**
	 * Validate and CMPP address for this CMPP version number.
	 */
	// public abstract boolean validateAddress(Address s);
	/**
	 * Validate the ESM class mandatory parameter.
	 */
	//public abstract boolean validateEsmClass(int c);

	/**
	 * Validate the Protocol ID mandatory parameter.
	 */
	//public abstract boolean validateProtocolID(int id);

	/**
	 * Validate the data coding mandatory parameter.
	 */
	//public abstract boolean validateDataCoding(int dc);

	/**
	 * Validate the default message ID mandatory parameter.
	 */
	//public abstract boolean validateDefaultMsg(int id);

	/**
	 * Validate the message text length.
	 */
	// public abstract boolean validateMessageText(String text,
	// AlphabetEncoding alphabet);
	/**
	 * Validate the length of the message bytes.
	 */
	// public abstract boolean validateMessage(byte[] message,
	// MessageEncoding encoding);
	/**
	 * Validate the service type mandatory parameter.
	 */
	//public abstract boolean validateServiceType(String type);

	/**
	 * Validate the message ID mandatory parameter.
	 */
	//public abstract boolean validateMessageId(String id);

	/**
	 * Validate the message state mandatory parameter. The message state and
	 * message status are the same. The name of the parameter changed between
	 * version 3.3 and version 3.4. The semantics, however, remain the same.
	 */
	//public final boolean validateMessageStatus(int st) {
	//	return (validateMessageState(st));
	//}

	/**
	 * Validate the message state mandatory parameter. The message state and
	 * message status are the same. The name of the parameter changed between
	 * version 3.3 and version 3.4. The semantics, however, remain the same.
	 */
	//public abstract boolean validateMessageState(int state);

	/**
	 * Validate the error code mandatory parameter.
	 */
	/*
	public abstract boolean validateErrorCode(int code);

	public abstract boolean validatePriorityFlag(int flag);

	public abstract boolean validateRegisteredDelivery(int flag);

	public abstract boolean validateReplaceIfPresent(int flag);

	public abstract boolean validateNumberOfDests(int num);

	public abstract boolean validateNumUnsuccessful(int num);

	public abstract boolean validateDistListName(String name);

	public abstract boolean validateSystemId(String sysId);

	public abstract boolean validatePassword(String password);

	public abstract boolean validateSystemType(String sysType);

	public abstract boolean validateAddressRange(String addressRange);

	public abstract boolean validateParamName(String paramName);

	public abstract boolean validateParamValue(String paramValue);
	*/

}
